/*
 *  Borum, Boolean rule manipulator.
 *  Copyright (C) 2009 Jon Lennersten, Johan Hedin, Daniel Rosenberg
 *
 *  This file is part of Borum.
 *
 *  Borum is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  Borum is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with Borum.  If not, see <http://www.gnu.org/licenses/>.
 */

package com.mawell.borum;

import net.antonioshome.swing.treewrapper.DeepCopyNode;
import org.simpleframework.xml.Root;
import org.simpleframework.xml.Attribute;
import org.simpleframework.xml.ElementList;

import java.util.List;

@Root
public class OperandNode extends DeepCopyNode {

    @Attribute
    OperandType type;

    @ElementList
    List<OperandNode> ops;

    @ElementList
    List<Term> terms;

    Translation trans;

    public OperandNode() {
    }

    public OperandNode(OperandType type) {
        this.type = type;
    }

    public OperandType getType() {
        return type;
    }

    public void setType(OperandType type) {
        this.type = type;
    }

    public List<OperandNode> getOps() {
        return ops;
    }

    public void setOps(List<OperandNode> ops) {
        this.ops = ops;
    }

    public List<Term> getTerms() {
        return terms;
    }

    public void setTerms(List<Term> terms) {
        this.terms = terms;
    }

    public Translation getTrans() {
        return trans;
    }

    public void setTrans(Translation trans) {
        this.trans = trans;
    }

    public DeepCopyNode deepCopy() {
        OperandNode copy = new OperandNode(this.type);
        copy.setTrans(trans);
        return copy;
    }

    public String toString() {
        switch(type) {
            case AND:
                return trans.getLabelForOpAND();
            case OR:
                return trans.getLabelForOpOR();
            default:
                return trans.getLabelForOpNOT();
        }
    }

    public boolean isLeaf() {
        return false;
    }
}
